/**
 * Created by chan on 2016/09/21.
 */


//cookie
 
$("#username").val($.cookie("merchanusername"));
$("#pass").val($.cookie("merchanpassword"));  
  

var main = {};
var myScroll;
(function ($) {
    main.init = function () {
        main.initEvent();
    };

    main.initEvent = function() { 
    	$("#confirm").on("click",login);
    };

    /** 
     * function 
     * merchant login
     */
    function login(){
    	var username=$("#username").val();
    	var password=$("#pass").val();
    	//ajax
    	$.ajax({
     		type:"post",
     		async:true, 
        	url:path+"/merchant/login",
        	data:{
        		username:username,
        		password:password,
        	},
     		success:function(data){	
     			if('000' == data.code){
     				var merchantid = data.result; 
     				 $.cookie("merchanusername", username, { expires: 7 , path: '/' }); // 存储一个带7天期限的 cookie
     			     $.cookie("merchanpassword", password, { expires: 7 , path: '/' }); // 存储一个带7天期限的 cookie
     				window.location.href=path+"/merchant/scanQrcode?merchantid="+merchantid;
     			}else{
     				common.alert({content:data.msg});
     			}
     		}
     	})
   		//ajax end
    }

})(jQuery);


main.init();

window.onload = function () {
	
};